<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1{
            width: 100px;
            height: 100px;
            background-color: aqua;
            position: relative;
        }
        .box2{
            width: 50px;
            height: 50px;
            background-color: red;
            /* 绝对定位 子绝父相*/
            position: absolute;
            top: 50%;
            left: 50%;
            /* 再移动自身一半的距离 */
            /* 可以用margin的方法实现 */
            /* margin-top: -25px;
            margin-left: -25px; */
            /* 用位移的方法实现 */
            transform: translate(-50%, -50%);
        }
    </style>
    </style>
</head>
<body>
    <div class="box1">
        <div class="box2"></div>
    </div>
</body>
</html>